home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 January
/
Macworld (1998-01).dmg
/
Shareware World
/
Comms & Internet
/
HTML mode 2.0 etc.
/
installScript.tcl
< prev
next >
Wrap
Text File
|
1997-08-17
|
11KB
|
340 lines
#===============================================================================
#
# installScript.tcl
#
# This file is used for installing HTML mode, CSS mode, JavaScript mode and Frontier menu.
#
# See the file READ ME TO INSTALL.
#
# Author: Johan Linde
#
#===============================================================================
# Find which version of HTML mode is in folder.
proc htmlGetHtmlVersion {folder} {
if {![file exists $folder:html.tcl]} {return "none"}
set cid [scancontext create]
set fid [open $folder:html.tcl]
scanmatch $cid "editing HTML documents" {
regexp {HTML mode ([^:]+)} $matchInfo(line) dum version
}
scanfile $cid $fid
close $fid
scancontext delete $cid
if {[info exists version]} {return [string trim $version]}
return "unknown"
}
# Find which version of object is in folder.
proc htmlGetVersion {folder object} {
if {$object == "htmlMode"} {return [htmlGetHtmlVersion $folder]}
if {![file exists $folder:$object.tcl]} {return "none"}
set cid [scancontext create]
set fid [open $folder:$object.tcl]
scanmatch $cid "Version:" {
regexp {Version:(.*)} $matchInfo(line) dum version
}
scanfile $cid $fid
close $fid
scancontext delete $cid
if {[info exists version]} {return [string trim $version]}
return "unknown"
}
proc htmlModeFileList {version} {
switch -glob $version {
1.1beta {set files {html.tcl htmlElems.tcl htmlEngine.tcl htmlLevels.tcl htmlMode.tcl}}
1.1 {set files {html.tcl htmlElems.tcl htmlEngine.tcl htmlLevels.tcl htmlMode.tcl}}
1.1.1 {set files {html.tcl htmlElems.tcl htmlEngine.tcl htmlExtra.tcl htmlLevels.tcl htmlMode.tcl}}
1.2* {set files {html.tcl htmlCustom.tcl htmlElems.tcl htmlEngine.tcl htmlExtra.tcl htmlMenu.tcl htmlMode.tcl}}
1.3* {set files {html.tcl htmlCustom.tcl htmlElems.tcl htmlEngine.tcl htmlExtra.tcl htmlMenu.tcl htmlMode.tcl htmlUtils.tcl}}
1.4* {set files {html.tcl htmlCustom.tcl htmlElems.tcl htmlEngine.tcl htmlExtra.tcl htmlMenu.tcl htmlMode.tcl htmlUtils.tcl}}
2.0* {set files {cssMode.tcl hctsmsl.tcl hctsmslMenu.tcl hctsmslShared.tcl html.tcl html32.tcl
htmlCustom.tcl htmlElems.tcl htmlEngine.tcl htmlExtensions.tcl htmlHomePageUtils.tcl htmlMenu.tcl htmlMode.tcl htmlStatusBar.tcl htmlUtils.tcl}}
default {set files {html.tcl htmlMode.tcl}}
}
return $files
}
proc javaScriptModeFileList {version} {
return javaScriptMode.tcl
}
proc frontierMenuFileList {version} {
return
}
proc htmlModeHelpFiles {version} {
return {"HTML Help"}
}
proc javaScriptModeHelpFiles {version} {
return
}
proc frontierMenuHelpFiles {version} {
return {"Frontier Help"}
}
proc htmlModeMenuFiles {version} {
return
}
proc javaScriptModeMenuFiles {version} {
return
}
proc frontierMenuMenuFiles {version} {
return frontierMenu.tcl
}
proc htmlBackupObject {version object installFolder} {
global HOME PREFS
set text(htmlMode) "HTML mode"
set text(javaScriptMode) "JavaScript mode"
set text(frontierMenu) "Frontier menu"
if {[file exists "$HOME:$text($object) $version backup"]} {
set i 1
while {[file exists "$HOME:$text($object) $version backup.$i"]} {
incr i
}
mkdir [set folder "$HOME:$text($object) $version backup.$i"]
} else {
mkdir [set folder "$HOME:$text($object) $version backup"]
}
copyFile "$installFolder:installScript.tcl" "$folder:installScript.tcl"
copyFile "$installFolder:READ ME TO INSTALL" "$folder:READ ME TO INSTALL"
foreach fil [eval ${object}FileList $version] {
if {[file exists "$HOME:Tcl:Modes:$fil"]} {
copyFile "$HOME:Tcl:Modes:$fil" "$folder:$fil"
} else {
lappend missing $fil
}
}
foreach fil [eval ${object}HelpFiles $version] {
if {[file exists "$HOME:Help:$fil"]} {
copyFile "$HOME:Help:$fil" "$folder:$fil"
} else {
lappend missing $fil
}
}
foreach fil [eval ${object}MenuFiles $version] {
if {[file exists "$HOME:Tcl:Menus:$fil"]} {
copyFile "$HOME:Tcl:Menus:$fil" "$folder:$fil"
} else {
lappend missing $fil
}
}
if {$object == "htmlMode" && [file exists "$PREFS:HTMLadditions.tcl"]} {copyFile "$PREFS:HTMLadditions.tcl" "$folder:HTMLadditions.tcl"}
if {[info exists missing] && [lindex [dialog -w 250 -h 200 \
-t "The old files $missing are missing.\rBackup of $text($object) is inscomplete. Continue installation of $text($object)?" 10 10 240 160 \
-b Continue 20 170 85 190 -b Cancel 105 170 170 190] 1]} {
error "Abort installation."
}
}
proc htmlRemoveObject {version object} {
global HOME
foreach fil [eval ${object}FileList $version] {
if {[file exists "$HOME:Tcl:Modes:$fil"]} {
removeFile "$HOME:Tcl:Modes:$fil"
}
}
foreach fil [eval ${object}HelpFiles $version] {
if {[file exists "$HOME:Help:$fil"]} {
removeFile "$HOME:Help:$fil"
}
}
foreach fil [eval ${object}MenuFiles $version] {
if {[file exists "$HOME:Tcl:Menus:$fil"]} {
removeFile "$HOME:Tcl:Menus:$fil"
}
}
}
proc htmlExtraBackup {fil} {
global HOME
set backup "$HOME:Extra backup"
if {[file exists $backup] && ![file isdirectory $backup]} {
set i 1
while {[file exists $backup.$i] && ![file isdirectory $backup]} {incr i}
set backup $backup.$i
}
if {![file exists "$backup"]} {mkdir "$backup"}
set newfile "$backup:[file tail $fil]"
if {[file exists $newfile]} {
set i 1
while {[file exists $newfile.$i]} {incr i}
set newfile "$newfile.$i"
}
copyFile $fil $newfile
removeFile $fil
}
proc htmlInstallObject {version object installFolder} {
global HOME PREFS
foreach fil [eval ${object}FileList $version] {
if {[file exists "$HOME:Tcl:Modes:$fil"]} {htmlExtraBackup "$HOME:Tcl:Modes:$fil"}
copyFile "$installFolder:$fil" "$HOME:Tcl:Modes:$fil"
}
foreach fil [eval ${object}HelpFiles $version] {
if {[file exists "$HOME:Help:$fil"]} {htmlExtraBackup "$HOME:Help:$fil"}
copyFile "$installFolder:$fil" "$HOME:Help:$fil"
}
foreach fil [eval ${object}MenuFiles $version] {
if {[file exists "$HOME:Tcl:Menus:$fil"]} {htmlExtraBackup "$HOME:Tcl:Menus:$fil"}
copyFile "$installFolder:$fil" "$HOME:Tcl:Menus:$fil"
}
if {$object == "htmlMode" && [string index $version 0] == "2"} {
catch {removeFile "$HOME:Tcl:Modes:htmlLevels.tcl"}
catch {removeFile "$HOME:Tcl:Modes:htmlExtra.tcl"}
}
if {$object == "htmlMode" && [file exists "$installFolder:HTMLadditions.tcl"]} {
catch {removeFile "$PREFS:HTMLadditions.tcl"}
copyFile "$installFolder:HTMLadditions.tcl" "$PREFS:HTMLadditions.tcl"
}
}
proc HTMLmodeInstaller {installFolder} {
global HOME PREFS
set text(htmlMode) "HTML mode"
set text(javaScriptMode) "JavaScript mode"
set text(frontierMenu) "Frontier menu"
set maxVers(htmlMode) {^1\.|^2\.0}
set maxVers(javaScriptMode) {^1\.0}
set maxVers(frontierMenu) {^1\.|^2\.0}
set minVers 6.2
# Build a dialog
set box "-t {Select what to install and what to backup} 50 10 350 30"
set h 50
foreach object {htmlMode javaScriptMode frontierMenu} {
set $object 1
set vers [htmlGetVersion $installFolder $object]
if {$vers == "none"} {
set $object 0
continue
}
if {$vers == "unknown"} {
alertnote "Could not find out which version of $text($object) there is in this folder. Can't install."
set $object 0
continue
}
if {![regexp $maxVers($object) $vers]} {
# Version to install is too new for this script.
alertnote "Sorry, don't know how to install $text($object) $vers."
continue
}
if {$object == "htmlMode" && [string index $vers 0] == "2"} {
set cssVers [htmlGetVersion $installFolder cssMode]
if {$cssVers == "none"} {
set $object 0
continue
}
if {$cssVers == "unknown"} {
alertnote "Could not find out which version of CSS mode there is in this folder. Can't install."
set $object 0
continue
}
}
set currFolder $HOME:Tcl:Modes
if {$object == "frontierMenu"} {set currFolder $HOME:Tcl:Menus}
set currVers [htmlGetVersion $currFolder $object]
if {$currVers != "none" && $currVers != "unknown" && ![regexp $maxVers($object) $currVers]} {
# Current version is to new for this script.
alertnote "$text($object) $currVers is installed. Can't replace it by $text($object) $vers."
continue
}
# Check that all files to install exist.
set allfound 1
foreach fil [concat [eval ${object}FileList vers] [eval ${object}HelpFiles $vers] [eval ${object}MenuFiles $vers]] {
if {![file exists "$installFolder:$fil"]} {
alertnote "The file $fil is missing. Can't install $object($text)."
set allfound 0
break
}
}
if {!$allfound} {continue}
set modetext "$text($object) $vers"
if {$object == "htmlMode" && [string index $vers 0] == "2"} {
append modetext " and CSS mode $cssVers"
set minVers 6.51
}
append box " -c [list $modetext] [expr (\"$vers\" != \"$currVers\")] 10 $h 350 [expr $h + 25]"
incr h 20
if {$object == "htmlMode" && [string index $currVers 0] == "2"} {set currCSS [htmlGetVersion $currFolder cssMode]}
set currtext "Currently installed: $currVers"
set backup$object 1
if {$currVers == "none"} {set backup$object 0}
if {$currVers == "unknown"} {set backup$object 0}
if {$object == "htmlMode" && [string index $currVers 0] == "2"} {append currtext " and $currCSS"}
append box " -t [list $currtext] 10 $h 350 [expr $h + 15]"
incr h 20
if {[set backup$object]} {append box " -c {Make backup before installing} [expr (\"$vers\" != \"$currVers\")] 30 $h 350 [expr $h + 15]"; incr h 20}
incr h 10
set new$object $vers
set curr$object $currVers
}
if {!$htmlMode && !$javaScriptMode && !$frontierMenu} {
alertnote "Found nothing to install."
}
# Check that Alpha is recent enough.
regexp {([0-9]+\.[0-9]+)[ab]?([0-9]*)} [version] dum Avers versbeta
if {$Avers < $minVers || ($Avers == $minVers && $versbeta != "")} {
alertnote "You need Alpha $minVers or later."
return
}
# Ask what to install.
set values [eval [concat dialog -w 360 -h [expr $h + 30] -b Install 20 $h 85 [expr $h + 20] \
-b Cancel 115 $h 180 [expr $h + 20] $box]]
if {[lindex $values 1]} {return}
# Make backups.
set i 1
foreach object {htmlMode javaScriptMode frontierMenu} {
if {![set $object]} {continue}
incr i
if {![set backup$object]} {continue}
incr i
if {![lindex $values [expr $i - 1]] || ![lindex $values $i]} {continue}
message "Making backup of $text($object) [set curr$object]…"
if {[catch {htmlBackupObject [set curr$object] $object $installFolder}]} {
alertnote "Making backup failed. Installation cancelled. No files have been deleted."
return
}
}
# Make installations
set installSomething 0
set i 1
foreach object {htmlMode javaScriptMode frontierMenu} {
if {![set $object]} {continue}
incr i
if {![lindex $values $i]} {
if {[set backup$object]} {incr i}
continue
}
if {[set backup$object]} {incr i}
set installSomething 1
message "Installing $text($object) [set new$object]…"
if {([set backup$object] && [catch {htmlRemoveObject [set curr$object] $object}]) || [catch {htmlInstallObject [set new$object] $object $installFolder}]} {
alertnote "Installation failed. Some of the old files may have been removed. Use the backup to reinstall the old version or try installing again."
return
}
}
if {!$installSomething} {alertnote "Nothing was installed."; return}
rebuildTclIndices
if {[lindex [dialog -w 300 -h 100 -t "Installation was successful. You must now restart Alpha." 10 10 290 50 \
-b Quit 20 70 85 90 -b Cancel 105 70 170 90] 0]} {quit}
}